package pathways;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.event.MouseEvent;

/**
 * Title:        Pathways
 * Description:  Pure Java version of the Pathways Project.
 * Copyright:    Copyright (c) 2002
 * Company:      Ants Technologies
 * @author Veejay Sani
 * @version 1.0
 */

public class CSubstrate extends CCompound
        implements IListenableItem
{
  public CSubstrate(String name, long ID) {
  /**
   * Constructor for non-graphical use of CSubstrate
   */
    super(name,ID);
    coords = new CCoOrdinates(new Rectangle(0,0,10,10)); // default rectangle
    visible = true;

    connP0 = new CConnectionPoint();
    connP1 = new CConnectionPoint();
    connP2 = new CConnectionPoint();
    connP3 = new CConnectionPoint();
  }

  public CSubstrate(String name, long ID, Rectangle rect) {
  /**
   * Constructor for graphical use of CSubstrate
   */
    super(name,ID);
    coords = new CCoOrdinates(rect);
    visible = true;

    connP0 = new CConnectionPoint();
    connP1 = new CConnectionPoint();
    connP2 = new CConnectionPoint();
    connP3 = new CConnectionPoint();
  }

  public CCoOrdinates getCoOrdinates()
  {
    return coords;
  }

  public Rectangle getRect()
  {
    return coords.getRect();
  }

  public Shape getShape()
  {
    return getRect();
  }

  public void eventOccurred(String eventName, MouseEvent e)
  {
    if (eventName.equals("mouseClicked"))
    {
        if (mouselistener != null)
          mouselistener.mouseClicked(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
    else if (eventName.equals("mouseEntered"))
    {
        if (mouselistener != null)
          mouselistener.mouseEntered(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
    else if (eventName.equals("mouseExited"))
    {
        if (mouselistener != null)
          mouselistener.mouseExited(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
    else if (eventName.equals("mousePressed"))
    {
        if (mouselistener != null)
          mouselistener.mousePressed(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
    else if (eventName.equals("mouseReleased"))
    {
        if (mouselistener != null)
          mouselistener.mouseReleased(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
    else if (eventName.equals("mouseDragged"))
    {
        if (mouselistener != null)
          mouselistener.mouseDragged(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
    else if (eventName.equals("mouseMoved"))
    {
        if (mouselistener != null)
          mouselistener.mouseMoved(new CSubstrateMouseEvent(this,e,eventName));
        else
          return;
    }
  }

  public CConnectionPoint getConnectionPoint(int pointNum)
  {
    if (pointNum == 0)
    {
      return getConnectionPoint0();
    }
    else if (pointNum == 1)
    {
      return getConnectionPoint1();
    }
    else if (pointNum == 2)
    {
      return getConnectionPoint2();
    }
    else
    {
      return getConnectionPoint3();
    }
  }

  public CConnectionPoint getConnectionPoint0()
  {
    return connP0;
  }

  public CConnectionPoint getConnectionPoint1()
  {
    return connP1;
  }

  public CConnectionPoint getConnectionPoint2()
  {
    return connP2;
  }

  public CConnectionPoint getConnectionPoint3()
  {
    return connP3;
  }

  public void draw(Graphics g, ISubstratePainter painter)
  {
    painter.draw(g,this);
  }

  public void addMouseListener(ISubstrateMouseListener listener)
  {
    mouselistener = listener;
  }

  public boolean isVisible()
  {
    return visible;
  }

  public void setVisible(boolean visibility)
  {
    visible = visibility;
  }

  private CCoOrdinates coords;
  private ISubstrateMouseListener mouselistener;
  private boolean visible;
  private CConnectionPoint connP0;
  private CConnectionPoint connP1;
  private CConnectionPoint connP2;
  private CConnectionPoint connP3;
}